﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        int[,] graph = null;
        Random rnd = new Random();
        using (StreamReader reader = new StreamReader(@"d:\Work\.NET\Workspace\GraphGen\GraphGen\test.txt"))
        {
            string line = reader.ReadLine();
            bool isFirstLine = true;
            while (line != null)
            {
                if (isFirstLine)
                {
                    isFirstLine = false;
                    int N = int.Parse(line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0]);
                    graph = new int[N, N]; 
                }
                else
                {
                    string[] values = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    int x = int.Parse(values[0]);
                    int y = int.Parse(values[1]);
                    //int value = int.Parse(values[2]);
                    graph[x - 1, y - 1] = rnd.Next(1, 101);
                }
                line = reader.ReadLine();
            }
        }

        StringBuilder graphMatrix = new StringBuilder();
        graphMatrix.AppendLine(graph.GetLength(0).ToString());

        for (int i = 0; i < graph.GetLength(0); i++)
        {
            for (int j = 0; j < graph.GetLength(0); j++)
            {
                graphMatrix.AppendFormat("{0}, ", graph[i, j]);
            }
            graphMatrix.Remove(graphMatrix.Length - 2, 1);
            graphMatrix.AppendLine();
        }

        Console.Write(graphMatrix.ToString());
    }
}

